﻿@{
	Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<div style="flex: 1;">
	<span style="float: left;margin-right: 10px;margin-top: 5px;">仓库编码</span>
	<input type="text" id="unitMeasureCode" name="unitMeasureCode" value="" placeholder="输入仓库编码" class="layui-input" lay-affix="clear" style="float: left;margin-right: 10px;width: 500px">
</div>
<div style="flex: 1;">
	<span style="float: left;margin-right: 10px;margin-top: 5px;">仓库名称</span>
	<input type="text" id="unitMeasureName" name="unitMeasureName" placeholder="输入仓库名称" class="layui-input" lay-affix="clear" style="float: left;margin-right: 10px;width: 500px">
</div>
<button class="layui-btn" id="searchmaterial">查询</button>
<button type="button" class="layui-btn" onclick="unitAdd()">添加</button>
<div style="margin-left: 20px;margin-top: 20px;">
	<table class="layui-hide" id="MeasurementUnitLists" lay-filter="MeasurementUnitLists" style="margin-top: 20px;margin-left: 20px">
	</table>
</div>
<script type="text/html" id="btn">
	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="upd">修改</a>
	<a class="layui-btn layui-btn-orange layui-btn-xs" lay-event="delete">删除</a>
</script>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
<script>

	function unitAdd(){
	  //iframe层
	  layui.layer.open({
		type: 2,
		title: '添加仓库设置',
		shadeClose: true,
		shade: 0.5,
		area: ['700px', '60%'],
		content: '/Warehousesetting/Add', //iframe的src
		end: function () {
			// iframe层关闭后刷新页面
			location.reload(); // 刷新页面
		}
	  });
	}

		layui.use(['table','form'], function () {
			var table = layui.table;
			var form = layui.form;
			var laydate = layui.laydate;

			 $(function(){
				getcumstiesm();

			})
			   //查询
			$('#searchmaterial').on('click',function(){
				 var unitMeasureCode=$('#unitMeasureCode').val();
					var unitMeasureName=$('#unitMeasureName').val();
					console.log(unitMeasureCode)
					console.log(unitMeasureName)
					table.reload('MeasurementUnitLists',{
						where:{
							codes:$('#unitMeasureCode').val(),
							name:$('#unitMeasureName').val()
						}
					})
			});

			function getcumstiesm(){
			// 渲染表格
			layui.table.render({
				elem: '#MeasurementUnitLists',
				url: '/Warehousesetting/WarehousesettingLists', // 实际接口地址
				toolbar: 'default',
				page: true, // 开启分页
				height: 400,
				limit: 10, // 每页默认显示的条数
				limits: [5, 10, 20, 30], // 每页条数的选择项
				cols: [[
						 { field: 'id', title: '编号', width: 130 },
						 { field: 'warehouseCode', title: '仓库编码', width: 130 },
						 { field: 'warehouseName', title: '仓库名称', width: 130 },
						 { field: 'location', title: '位置', width: 130 },
						 { field: 'warehouseArea', title: '面积', width: 130 },
						 { field: 'warehouseHead', title: '负责人', width: 130 },
						 {field: 'isFreeze',title: '是否启用',templet: function (d) {
								 return d.isFreeze==1 ? '是' : '否';
							  }
						 },
						 { title: '操作', fixed: 'right', width: 300, align: 'center', toolbar: '#btn' }
						]]
				});
			}

			layui.table.on('tool(MeasurementUnitLists)', function (obj) {
			  var data = obj.data;
			  if (obj.event === 'delete') {
				layer.confirm('确定要删除吗？', function (index) {
					$.ajax({
						url: "/Warehousesetting/DeleteWarehousesetting", // 替换成实际的删除接口地址
						type: "get", // 或者 "GET"，根据实际接口要求
						data: {
							id: data.id // 将删除需要的参数传递给后端，这里假设删除操作需要 id 参数
						},
						success: function (res) {
							if (res >= 1) {
								layer.msg('删除成功');
								// 这里可以根据业务需求，刷新表格数据或者进行其他操作
								table.reload('MeasurementUnitLists');
							} else {
								layer.msg('删除失败: ' + res.msg);
							}
						},
						error: function (xhr, status, error) {
							console.error('删除请求出错', error);
							layer.msg('删除请求出错，请重试');
						}
					});
				})
			  }else if (obj.event === 'upd') {
				layui.layer.open({
					type: 2,
					title: '编辑计量单位',
					shadeClose: true,
					shade: 0.5,
					area: ['800px', '600px'],
					content: '/Warehousesetting/Upd?id=' + data.id,
					end: function () {
						// iframe层关闭后刷新页面
						location.reload(); // 刷新页面
					}
				});
			  }

			})
		});
</script>